package com.lagou.seaech.controller;

import com.lagou.entity.Result;
import com.lagou.entity.StatusCode;
import com.lagou.seaech.service.SearchService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Fxz
 * @version 1.0
 * @date 2021-10-05 21:27
 */
@RequestMapping("/search")
@AllArgsConstructor
@RestController
public class SearchController {

    private final SearchService searchService;

    /**
     * 商品搜索
     *
     * @param paramMap
     * @return
     * @throws Exception
     */
    @GetMapping
    public Map search(@RequestParam Map<String, String> paramMap) throws Exception {
        Map resultMap = searchService.search(paramMap);
        return resultMap;
    }

    @GetMapping("/createIndexAndMapper")
    public Result createIndexAndMapper() {
        searchService.createIndexAndMapping();
        return new Result(true, StatusCode.OK, "创建成功~", null);
    }

    /**
     * 导入所有符合上架条件的SKU列表
     *
     * @return
     */
    @GetMapping("/importAllSkuList")
    public Result importAllSkuList() {
        searchService.importAll();
        return new Result(true, StatusCode.OK, "导入成功~", null);
    }
}
